PHP Fingerprinting CMS Versions by their meta tags [migrated]

Posted by Mud on Programmers See other posts from Programmers or by Mud
Published on 2013-10-25T11:32:20Z Indexed on 2013/10/25 16:10 UTC
Read the original article Hit count: 217

Filed under:
|
|
|

Hey guys I'm having some issues with the speed of my script. I'm a novice I know so getting past that - what suggestions would you have to speed up my script?

I was originally just reading in the index.php and then searching the <head> of the page for an array of strings. Then I read about the get_meta_tags and went that way. Then I had issues with some sites having 300 redirects in place so I used curl to check the URL existed and to speed up things but it's still taking 5 minutes or so to execute.

<?php
function url_exist($url){
        $c=curl_init();
        curl_setopt($c,CURLOPT_URL,$url);
        curl_setopt($c,CURLOPT_HEADER,1);
        curl_setopt($c,CURLOPT_NOBODY,1);
        curl_setopt($c,CURLOPT_RETURNTRANSFER,1);
        curl_setopt($c,CURLOPT_FRESH_CONNECT,1);
        if(!curl_exec($c)){
        return false;
        }else{
        return true;
        }
        curl_close($c);
    }


function checkVersion($url){

    $tags = get_meta_tags($url);

    if (is_array($tags) && array_key_exists('generator', $tags))
    {      
        $v = "<span style='background-color:#7BF55D;color:#A3A0A0'>".$tags['generator']."</span";       
    }else{
        $v="<span style='background-color:#F55D67;color:#A3A0A0'>Metatag not found!</span>";
    }


 return $v;
}


$row = 1;
echo "<table>";

if (($handle = fopen("url.csv", "r")) !== FALSE) {
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
        $num = count($data);

        $row++;
        for ($c=0; $c < $num; $c++) {
            if(url_exist($data[$c])){
            echo "<tr><td>".$data[$c]."</td><td>".checkVersion($data[$c])."</td></tr>";
            sleep(2);
        }else{
            echo "<tr><td>".$data[$c]."</td><td><td><span style='background-color:#F55D5D;color:#A3A0A0'>URL not valid!<span></td></tr>";
        }


        }
    }
    fclose($handle);
}

echo "</table>";


?>

© Programmers or respective owner

Related posts about php

Related posts about cms